home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 16.4 KB | 547 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UCalcRows.cp
- // Copyright © 1986-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #ifndef __UCALCROWS__
- #include "UCalcRows.h"
- #endif
-
- // Calc
-
- #ifndef __UCALCCOLUMNS__
- #include "UCalcColumns.h"
- #endif
-
- #ifndef __UCALCROWS__
- #include "UCalcRows.h"
- #endif
-
- #ifndef __UCALCCELLS__
- #include "UCalcCells.h"
- #endif
-
- // MacApp
-
- // Toolbox
-
- // ANSI
-
- #ifndef __STDIO__
- #include <stdio.h>
- #endif
-
- #ifndef __STDLIB__
- #include <stdlib.h>
- #endif
-
- //========================================================================================
- // CLASS TRowsView
- //========================================================================================
- #undef Inherited
- #define Inherited TTextGridView
-
- #pragma segment ClassDescRes
- MA_DEFINE_CLASS_M1(TRowsView, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TRowsView::DoPostCreate:
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- void TRowsView::DoPostCreate(TDocument* itsDocument) // override
- {
- fCalcDocument = (TCalcDocument *)(itsDocument);
- fHelpID = kRowsViewHelp;
- fHelpIndex = 2;
- } // TRowsView::DoPostCreate
-
- //----------------------------------------------------------------------------------------
- // TRowsView destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TRowsView::~TRowsView()
- {
- }
-
-
- //----------------------------------------------------------------------------------------
- // TRowsView::AdornRow:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TRowsView::AdornRow(short /*aRow*/,
- const VRect& area)// override
- {
- PenSize(1, 1);
- PenPat(&qd.black);
-
- CRect qdArea(ViewToQDRect(area));
- // right line
- MoveTo(qdArea.right - 1, qdArea.top);
- LineToPt(qdArea[botRight] - CPoint(1, 1));
-
- // bottom line
- MoveTo(qdArea.left, qdArea.bottom - 1);
- LineToPt(qdArea[botRight] - CPoint(1, 1));
- } // TRowsView::AdornRow
-
-
- //----------------------------------------------------------------------------------------
- // TRowsView::DoMouseCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- void TRowsView::DoMouseCommand(VPoint& theMouse,
- TToolboxEvent* event,
- CPoint /*hysteresis*/) // override
- {
- TRowSelector * aRowSelector;
-
- aRowSelector = new TRowSelector;
- aRowSelector->IRowSelector(fCalcDocument, this, theMouse, event->IsShiftKeyPressed(), event->IsCommandKeyPressed());
- this->PostCommand(aRowSelector);
- fCalcDocument->fSelectionType = kRowSelection;
- fCalcDocument->fColumnsView->SetEmptySelection(kHighlight);
- fCalcDocument->fColumnIsSelected = FALSE;
- } // TRowsView::DoMouseCommand
-
-
- //----------------------------------------------------------------------------------------
- // TRowsView::DoSetCursor:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TRowsView::DoSetCursor(const VPoint& globalMouse,
- RgnHandle cursorRegion)// override
- {
- //!!! DoSetCursor = false;
- Inherited::DoSetCursor(globalMouse, cursorRegion);
- } // TRowsView::DoSetCursor
-
-
- //----------------------------------------------------------------------------------------
- // TRowsView::DrawCell:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TRowsView::DrawCell(GridCell aCell,
- const VRect& aRect)// override
- {
- CStr255 theString;
- NumToString(aCell.v, theString);
-
- CRect qdArea(this->ViewToQDRect(aRect));
- qdArea.top = qdArea.top + 2; // aesthetic adjustment of the CRect
- MADrawString(theString, qdArea, teCenter);
- } // TRowsView::DrawCell
-
-
- //========================================================================================
- // CLASS TRow
- //========================================================================================
- #undef Inherited
- #define Inherited TObject
-
- #pragma segment ClassDescRes
- MA_DEFINE_CLASS_M1(TRow, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TRow constructor
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- TRow::TRow()
- {
- fNumber = 0;
- } // TRow::TRow
-
- //----------------------------------------------------------------------------------------
- // TRow destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TRow::~TRow()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TRow::IRow:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TRow::IRow(short number)
- {
- this->IObject();
-
- fNumber = number;
- } // TRow::IRow
-
-
- //----------------------------------------------------------------------------------------
- // TRow::ReadFromDisk:
- //----------------------------------------------------------------------------------------
- #pragma segment AReadFile
-
- void TRow::ReadFromDisk(TFile* aFile)
- {
- RowDiskInfo rowInfo;
- long count;
-
- count = sizeof(RowDiskInfo);
- FailOSErr(aFile->ReadData(&rowInfo, count));
- fNumber = rowInfo.number;
- } // TRow::ReadFromDisk
-
-
- //----------------------------------------------------------------------------------------
- // TRow::WriteToDisk:
- //----------------------------------------------------------------------------------------
- #pragma segment AWriteFile
-
- void TRow::WriteToDisk(TFile* aFile)
- {
- RowNumber r;
- RowDiskInfo rowInfo;
- long count;
-
- // need to write our row number which is read in in TCalcDocument.DoRead
- r = fNumber;
- count = sizeof(RowNumber);
- FailOSErr(aFile->WriteData(&r, count));
-
- // now, write out the info that TRow.ReadFromDisk expects to see
- rowInfo.number = fNumber;
- count = sizeof(RowDiskInfo);
- FailOSErr(aFile->WriteData(&rowInfo, count));
- } // TRow::WriteToDisk
-
-
- //----------------------------------------------------------------------------------------
- // TRow::ReadFromScrap:
- //----------------------------------------------------------------------------------------
- #pragma segment AClipBoard
-
- void TRow::ReadFromScrap(Handle theScrap,
- long& scrapOffset)
- {
- RowDiskInfo RowInfo;
-
- ReadScrap(theScrap, scrapOffset, (unsigned char*) & RowInfo, sizeof(RowInfo));
- fNumber = RowInfo.number;
- } // TRow::ReadFromScrap
-
-
- //----------------------------------------------------------------------------------------
- // TRow::WriteToScrap:
- //----------------------------------------------------------------------------------------
- #pragma segment AClipBoard
-
- void TRow::WriteToScrap(Handle theScrap,
- long& scrapOffset)
- {
- RowDiskInfo RowInfo;
-
- RowInfo.number = fNumber;
- WriteScrap(theScrap, scrapOffset, (unsigned char*) & RowInfo, sizeof(RowInfo));
- } // TRow::WriteToScrap
-
-
- //========================================================================================
- // CLASS TRowList
- //========================================================================================
- #undef Inherited
- #define Inherited TSortedList
-
- #pragma segment ClassDescRes
- MA_DEFINE_CLASS_M1(TRowList, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TRowList destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TRowList::~TRowList()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TRowList::IRowList:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TRowList::IRowList()
- {
- this->ISortedList();
- } // TRowList::IRowList
-
-
- //----------------------------------------------------------------------------------------
- // TRowList::Compare:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- CompareResult TRowList::Compare(TObject* item1,
- TObject* item2)// override
- {
- // like TCellList and TColumnList, we are guaranteed a homogenous list (Rows this case)
- // so typecasting is perfectly safe.
-
- if (((TRow *)(item1))->fNumber > ((TRow *)(item2))->fNumber)
- return kItem1GreaterThanItem2;
- else if (((TRow *)(item1))->fNumber < ((TRow *)(item2))->fNumber)
- return kItem1LessThanItem2;
- else
- return kItem1EqualItem2;
- } // TRowList::Compare
-
-
- //----------------------------------------------------------------------------------------
- // TRowList::GetRow:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- TRow* TRowList::GetRow(RowNumber r)
- {
- CCalcRowIterator iter(this); // initialize the row iterator to find the row
-
- for (TRow * aRow = iter.FirstRow(); iter.More(); aRow = iter.NextRow())
- if (aRow->fNumber == r)
- return aRow; // as soon as we find it, leave the method call
-
- return NULL; // if we get here, that means that we didn't find it
- } // TRowList::GetRow
-
-
- //========================================================================================
- // CLASS TRowSelector
- //========================================================================================
- #undef Inherited
- #define Inherited TCalcSelectCommand
-
- #pragma segment ClassDescRes
- MA_DEFINE_CLASS_M1(TRowSelector, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TRowSelector::TRowSelector:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- TRowSelector::TRowSelector()
- {
- fCellSelector = NULL;
- } // TRowSelector::TRowSelector
-
- //----------------------------------------------------------------------------------------
- // TRowSelector::IRowSelector:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- void TRowSelector::IRowSelector(TCalcDocument* itsDocument,
- TGridView* itsView,
- VPoint& theMouse,
- Boolean theShiftKey,
- Boolean theCommandKey)
- {
- this->ICellSelectCommand(itsView, theMouse, theShiftKey, theCommandKey);
-
- fCalcDocument = itsDocument;
-
- if (fCalcDocument->fSelectionType != kRowSelection)
- theCommandKey = FALSE;
-
- MAVolatileInit(TCalcSelectCommand*, aCellSelector, NULL);
-
- FailInfo fi;
- Try(fi)
- {
- aCellSelector = new TCalcSelectCommand;
- aCellSelector->ICalcSelectCommand(itsDocument, itsDocument->fCellsView, theMouse, theShiftKey, theCommandKey);
- fi.Success();
- }
- else
- {
- aCellSelector = (TCalcSelectCommand*) FreeIfObject(aCellSelector);
- this->Free();
- fi.ReSignal();
- }
- fCellSelector = aCellSelector;
- } // TRowSelector::IRowSelector
-
-
- //----------------------------------------------------------------------------------------
- // TRowSelector::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- TRowSelector::~TRowSelector() // override
- {
- fCellSelector = (TCalcSelectCommand *)(FreeIfObject(fCellSelector));
- } // TRowSelector::Free
-
-
- //----------------------------------------------------------------------------------------
- // TRowSelector::ComputeAnchorCell:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TRowSelector::ComputeAnchorCell(GridCell& clickedCell)// override
- {
- Inherited::ComputeAnchorCell(clickedCell);
-
- fAnchorCell.h = 1;
- clickedCell.h = 1;
- fCellSelector->ComputeAnchorCell(clickedCell);
- } // TRowSelector::ComputeAnchorCell
-
-
- //----------------------------------------------------------------------------------------
- // TRowSelector::ComputeNewSelection:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TRowSelector::ComputeNewSelection(GridCell& clickedCell)// override
- {
- CRect r;
-
- clickedCell.h = fGridView->fNumOfCols;
- Inherited::ComputeNewSelection(clickedCell);
-
- clickedCell.h = fCalcDocument->fNoOfColumns;
- fCellSelector->ComputeNewSelection(clickedCell);
- } // TRowSelector::ComputeNewSelection
-
-
- //----------------------------------------------------------------------------------------
- // TRowSelector::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TRowSelector::DoIt() // override
- {
- Inherited::DoIt();
- fCellSelector->DoIt();
- } // TRowSelector::DoIt
-
-
- //----------------------------------------------------------------------------------------
- // TRowSelector::TrackMouse:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- TTracker* TRowSelector::TrackMouse(TrackPhase aTrackPhase,
- VPoint& /*anchorPoint*/,
- VPoint& /*previousPoint*/,
- VPoint& nextPoint,
- Boolean mouseDidMove)// override
- {
- GridCell clickedCell;
-
- if (mouseDidMove)
- {
- clickedCell = fGridView->VPointToCell(nextPoint);
- if (aTrackPhase == trackBegin)
- {
- this->ComputeAnchorCell(clickedCell);
- if (fCommandKey)
- {
- fDeselecting = PtInRgn(fAnchorCell, fGridView->fSelections);
- fCellSelector->fDeselecting = fDeselecting;
- }
- }
-
- if (clickedCell != fPreviousCell)
- {
- this->ComputeNewSelection(clickedCell);
- this->HighlightNewSelection();
- fCellSelector->HighlightNewSelection();
-
- CopyRgn(fThisSelection, fPreviousSelection);
- fPreviousCell = clickedCell;
- CopyRgn(fCellSelector->fThisSelection, fCellSelector->fPreviousSelection);
- fCellSelector->fPreviousCell = clickedCell;
- }
- }
- return this;
- } // TRowSelector::TrackMouse
-
-
-
- //========================================================================================
- // CLASS CCalcRowIterator
- //========================================================================================
- #undef Inherited
-
- //----------------------------------------------------------------------------------------
- // CCalcRowIterator::CCalcRowIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- CCalcRowIterator::CCalcRowIterator(TCalcDocument* theCalcDocument) :
- CObjectIterator(theCalcDocument ? theCalcDocument->fRows : NULL)
- {
- } // CCalcRowIterator::CCalcRowIterator
-
-
- //----------------------------------------------------------------------------------------
- // CCalcRowIterator::CCalcRowIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- CCalcRowIterator::CCalcRowIterator(TRowList* theRowList) :
- CObjectIterator(theRowList)
- {
- } // CCalcRowIterator::CCalcRowIterator
-
-
- //----------------------------------------------------------------------------------------
- // CCalcRowIterator::~CCalcRowIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- CCalcRowIterator::~CCalcRowIterator()
- {
- } // CCalcRowIterator::~CCalcRowIterator
-
-
- //----------------------------------------------------------------------------------------
- // CCalcRowIterator::CurrentRow:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- TRow* CCalcRowIterator::CurrentRow()
- {
- // returns the current Row
- return (TRow *)this->CurrentObject();
- } // CCalcRowIterator::CurrentRow
-
-
- //----------------------------------------------------------------------------------------
- // CCalcRowIterator::FirstRow:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- TRow* CCalcRowIterator::FirstRow()
- {
- // return the first Row in the iteration
- return (TRow *)this->FirstObject();
- } // CCalcRowIterator::FirstRow
-
-
- //----------------------------------------------------------------------------------------
- // CCalcRowIterator::NextRow:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- TRow* CCalcRowIterator::NextRow()
- {
- // advances the iteration and then returns the Row
- return (TRow *)this->NextObject();
- } // CCalcRowIterator::NextRow
-
- //----------------------------------------------------------------------------------------
- // End of UCalcRows.cp
-
- #pragma segment Inline
-